package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.mapper.UserMapper;
import com.woniuxy.model.UserInfo;
import com.woniuxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /*
    * 查询所有用户信息
    * */
    @Override
    public List<UserInfo> getAll() {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        List<UserInfo> userInfos = userMapper.selectList(queryWrapper);
        return userInfos;
    }

    /*查询指定id的用户信息*/
    @Override
    public UserInfo getByUserId(Integer uid) {
        UserInfo userInfo = userMapper.selectById(uid);
        return userInfo;
    }

    //根据用户信息进行新增用户
    @Override
    public void addUser(UserInfo userInfo) {
        userMapper.insert(userInfo);
    }

    //根据ids批量删除用户
    @Override
    public void deleteBatch(String s) {
        String[] split = s.split(",");
        List<Integer> ids = new ArrayList<>();
        for(String id:split){
            ids.add(Integer.parseInt(id));
        }
        userMapper.deleteByIds(ids);
    }

    //修改用户信息，根据传入的用户Id
    @Override
    public void modifyUser(UserInfo userInfo) {
        userMapper.insertOrUpdate(userInfo);
    }
}
